package com.systar.activity.events;

import java.nio.ByteBuffer;

import com.systar.activity.monitor.ActivitySource;

public class StatusActivityEvent extends AbstractActivityEvent
{
	public static final String TYPE = "status";

	private boolean active;

	public StatusActivityEvent(ActivitySource source, boolean enable)
	{
		setSource(source);
		this.active = enable;
	}

	public boolean isActive()
	{
		return active;
	}

	@Override
	public String getType()
	{
		return TYPE;
	}

	@Override
	public String getMessage()
	{
		return getSourceName() + " is now " + (active ? "active" : "idle");
	}

	@Override
	public void concat(IActivityEvent otherEvent)
	{
		if (!getType().equals(otherEvent.getType()))
			return;
		
		StatusActivityEvent other = (StatusActivityEvent)otherEvent;
		active = other.active;
	}

	@Override
	public String marshal()
	{
		return super.marshal() + Boolean.toString(active);
	}

	@Override
	public void marshal(ByteBuffer data)
	{
		data.position(0);
		data.put((byte) (active ? 1 : 0));
	}

}
